from rest_framework import serializers
from .models import *


class TaskSerializer(serializers.ModelSerializer):
    class Meta:
        model = Task
        # exclude = ['id', 'ban_create_info'] #排除
        # fields = ["id", "username", "password", "ooo", "rls"] #包含
        fields = '__all__'  # 全部字段


class TaskListSerializer(serializers.ModelSerializer):
    targets = TaskSerializer(many=True, required=False)
    time = serializers.DateTimeField(format="%Y-%m-%d %H:%M:%S", required=False)

    class Meta:
        model = Task
        fields = '__all__'
        read_only_fields = ['id']


# 根据id查询
class TaskIDSerializer(serializers.ModelSerializer):
    time = serializers.DateTimeField(format="%Y-%m-%d %H:%M:%S", required=False, read_only=True)

    class Meta:
        model = Task
        fields = '__all__'
        read_only_fields = ['id']

